#include <iostream>

using namespace std;

int main()
{
    int q;
    cin >> q;
    for (int i=1; i<=q; ++i)
    {
        long long inp;
        cin >> inp;
        int ans = 0;
        while (inp != 1)
        {
            if (inp%5==0) {inp /= 5; ans+=3;continue;}
            if (inp%3==0) {inp /= 3; ans+=2;continue;}
            if (inp%2==0) {inp /= 2; ans+=1;continue;}
            ans = -1; break;
        }
        cout << ans << endl;
    }
    return 0;
}
/*

7
1
10
25
30
14
27
1000000000000000000

*/
